package kitwee.com.kanpad.bean;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import kitwee.com.kanpad.R;
import kitwee.com.kanpad.orderDetail.SerialPortDataModel;
import kitwee.com.kanpad.orderDetail.SerualPortName;

/**
 * @author GanQuan
 * @date 2018/1/25
 * kitwee.com.kanpad.bean
 */

public class SerialPortAdapter extends RecyclerView.Adapter<SerialPortAdapter.ViewHolder> {


    private Context context;
    private List<SerialPortDataModel> realTimeBeanList;

//    private List<Pair<String, String>> data;
    private List<Pair<String, Integer>> data;

//    public SerialPortAdapter(Context context, List<SerialPortDataModel> realTimeBeanList) {
//        this.context = context;
//        this.realTimeBeanList = realTimeBeanList;
//    }


    public SerialPortAdapter(Context context) {
        this.context = context;
        this.data = new ArrayList<>();
    }

    public void setData(List<Pair<String, Integer>> data) {
//        this.data = data;
        if (data != null) {
            int previousSize = data.size();
            this.data.clear();
            notifyItemRangeRemoved(0, previousSize);
            this.data.addAll(data);
            notifyItemRangeInserted(0, data.size());
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.real_time_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
//        holder.status.setText(""+ realTimeBeanList.get(position).getDT32524());
//        holder.projectName.setText(""+ realTimeBeanList.get(position).getDT32759());
//        holder.realData.setText(""+ realTimeBeanList.get(position).getDT32761());
//        holder.standard.setText(""+ realTimeBeanList.get(position).getDT32763());
        holder.status.setText(""+data.get(position).first);
        holder.projectName.setText(""+data.get(position).second);
    }

    public String getSerialPortName(String serialPortValue) {
        switch (serialPortValue) {

            case "DT140":
                return SerualPortName.DT140;
            case "DT142":
                return SerualPortName.DT142;
            case "DT32450":
                return SerualPortName.DT32450;
            case "DT32472":
                return SerualPortName.DT32472;
            case "DT32474":
                return SerualPortName.DT32474;
            case "DT32476":
                return SerualPortName.DT32476;
            case "DT32478":
                return SerualPortName.DT32478;
            case "DT32482":
                return SerualPortName.DT32482;
            case "DT32495":
                return SerualPortName.DT32495;
            case "DT32500":
                return SerualPortName.DT32500;
            case "DT32502":
                return SerualPortName.DT32502;
            case "DT32504":
                return SerualPortName.DT32504;
            case "DT32506":
                return SerualPortName.DT32506;
            case "DT32514":
                return SerualPortName.DT32514;
            case "DT32522":
                return SerualPortName.DT32522;
            case "DT32524":
                return SerualPortName.DT32524;
            case "DT32528":
                return SerualPortName.DT32528;
            case "DT32529":
                return SerualPortName.DT32529;
            case "DT32530":
                return SerualPortName.DT32530;
            case "DT32532":
                return SerualPortName.DT32532;
            case "DT32534":
                return SerualPortName.DT32534;
            case "DT32540":
                return SerualPortName.DT32540;
            case "DT32542":
                return SerualPortName.DT32542;
            case "DT32700":
                return SerualPortName.DT32700;
            case "DT32710":
                return SerualPortName.DT32710;
            case "DT32713":
                return SerualPortName.DT32713;
            case "DT32714":
                return SerualPortName.DT32714;
            case "DT32716":
                return SerualPortName.DT32716;
            case "DT32717":
                return SerualPortName.DT32717;
            case "DT32729":
                return SerualPortName.DT32729;
            case "DT32730":
                return SerualPortName.DT32730;
            case "DT32743":
                return SerualPortName.DT32743;
            case "DT32745":
                return SerualPortName.DT32745;
            case "DT32747":
                return SerualPortName.DT32747;
            case "DT32749":
                return SerualPortName.DT32749;
            case "DT32759":
                return SerualPortName.DT32759;
            case "DT32761":
                return SerualPortName.DT32761;
            case "DT32763":
                return SerualPortName.DT32763;
            case "R1051":
                return SerualPortName.R1051;
            case "R13":
                return SerualPortName.R13;
            case "R145":
                return SerualPortName.R145;
            case "R146":
                return SerualPortName.R146;
            case "R148":
                return SerualPortName.R148;
            case "R151":
                return SerualPortName.R151;
            case "R152":
                return SerualPortName.R152;
            case "R153":
                return SerualPortName.R153;
            case "R154":
                return SerualPortName.R154;
            case "R155":
                return SerualPortName.R155;
            case "R5B":
                return SerualPortName.R5B;
            case "R62":
                return SerualPortName.R62;
            case "R64":
                return SerualPortName.R64;
            case "R66":
                return SerualPortName.R66;
            case "R1053":
                return SerualPortName.R1053;
            case "R1054":
                return SerualPortName.R1054;
            case "R122":
                return SerualPortName.R122;
            case "R123":
                return SerualPortName.R123;
            case "R68":
                return SerualPortName.R68;
            case "DT214":
                return SerualPortName.DT214;
            //展厅
            case "DT32712":
                return SerualPortName.DT32712;
            case "DT32720":
                return SerualPortName.DT32720;
        }
        return "不明参数";
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.status)
        TextView status;
        @BindView(R.id.project_name)
        TextView projectName;
        @BindView(R.id.real_data)
        TextView realData;
        @BindView(R.id.standard)
        TextView standard;
        @BindView(R.id.unit)
        TextView unit;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }


}
